package com.fenghuajueli.lib_pictureselect.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

import com.blankj.utilcode.util.ConvertUtils;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;

import java.util.List;

public class SelectMediaTabAdapter extends CommonNavigatorAdapter {

    private List<String> tabTitleList;
    private ViewPager viewPager;

    public SelectMediaTabAdapter(List<String> tabTitleList) {
        this.tabTitleList = tabTitleList;
    }

    public void setViewPager(ViewPager viewPager) {
        this.viewPager = viewPager;
    }

    @Override
    public int getCount() {
        return tabTitleList.size();
    }

    @Override
    public IPagerTitleView getTitleView(Context context, int index) {
        ColorTransitionPagerTitleView colorTransitionPagerTitleView = new ColorTransitionPagerTitleView(context);
        colorTransitionPagerTitleView.setText(tabTitleList.get(index));
        colorTransitionPagerTitleView.setPadding(ConvertUtils.dp2px(18),0,ConvertUtils.dp2px(18),0);
        colorTransitionPagerTitleView.setNormalColor(Color.parseColor("#50ffffff"));
        colorTransitionPagerTitleView.setSelectedColor(Color.parseColor("#FFFFFF"));
        colorTransitionPagerTitleView.setTextSize(16);
        colorTransitionPagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (viewPager!=null) {
                    viewPager.setCurrentItem(index,false);
                }
            }
        });
        return colorTransitionPagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator indicator = new LinePagerIndicator(context);
        indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
        indicator.setLineWidth(ConvertUtils.dp2px(20));
        indicator.setColors(Color.parseColor("#FFFFFF"));
        return indicator;
    }
}
